Chain of Responsibility

Table of Contents

1. Chain of Responsibility

Chain of responsibility is about splitting one large task with sequential and complicated requirements into non-overlapping handlers.

CoR suggests that these /handlers should be linked into a chain, where each handler has a field storing a reference to the next handler.

In addition to processing the request, handlers should pass the request further to next handler. Moreover, handlers can decide not to pass the request and thus stop further processing. An example for this could be authentication, that failure in any part should remark the failure of whole procedure.

Another version of CoR is that, handlers check if they can process it, if yes, then ends here; otherwise, the request will be passed further. A typical scenario is UI interaction.

1.1. Scenarios

Here, we cover some common scenarios that we can use chain of responsibility.

  1. when the program is expected to process different kinds of requests in various ways, but the types of requests and their sequences are unknown beforehand.
  2. when it’s essential to execute several handlers in a particular order
  3. when the set of handlers and their order are supposed to change at runtime

Date: 2026-05-30 Sat 00:00